package com.tkk.monitoring.analyze.config;

import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Pattern;

/**
 * Created by Administrator on 2015/7/9.
 */
public class Property extends Config {
    private Properties properties;

    public Property(String filePath) {
        super(filePath);
        properties = new Properties();
        try {
            properties.load(getInputStream());
        } catch (IOException e) {
        }
    }

    public String getString(String key) {
        return properties.getProperty(key);
    }

    public Pattern getPattern(String key) {
        return Pattern.compile(getString(key), Pattern.CASE_INSENSITIVE);
    }

    public List<String> find(String reg) {
        Set<Object> objects = properties.keySet();
        List<String> r = new LinkedList<String>();
        for (Object object : objects) {
            if (reg != null && object.toString().matches(reg)) {
                r.add(properties.getProperty(object.toString()));
            }
        }
        return r;
    }
}
